<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Opens an existing large object stream</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="pdo.pgsqllobcreate.html">« PDO::pgsqlLOBCreate</a></li>
      <li style="float: right;"><a href="pdo.pgsqllobunlink.html">PDO::pgsqlLOBUnlink »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.pdo-pgsql.html">PostgreSQL (PDO)</a></li>
    <li>Opens an existing large object stream</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="pdo.pgsqllobopen" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">PDO::pgsqlLOBOpen</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.2, PHP 7, PHP 8, PECL pdo_pgsql &gt;= 1.0.2)</p><p class="refpurpose"><span class="refname">PDO::pgsqlLOBOpen</span> &mdash; <span class="dc-title">Opens an existing large object stream</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-pdo.pgsqllobopen-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>PDO::pgsqlLOBOpen</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$oid</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$mode</code><span class="initializer"> = &quot;rb&quot;</span></span>): <span class="type"><span class="type">resource</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>PDO::pgsqlLOBOpen()</strong></span> opens a stream to access the data
   referenced by <code class="parameter">oid</code>.  If <code class="parameter">mode</code>
   is <code class="literal">r</code>, the stream is opened for reading, if
   <code class="parameter">mode</code> is <code class="literal">w</code>, then the stream will
   be opened for writing.  You can use all the usual filesystem functions,
   such as <span class="function"><a href="function.fread.html" class="function">fread()</a></span>, <span class="function"><a href="function.fwrite.html" class="function">fwrite()</a></span> and
   <span class="function"><a href="function.fgets.html" class="function">fgets()</a></span> to manipulate the contents of the stream.
  </p>
   <blockquote class="note"><p><strong class="note">注意</strong>: 
   <span class="simpara">
    This function, and all manipulations of the large object,
    must be called and carried out within a transaction.
   </span>
  </p></blockquote>
</div>

 <div class="refsect1 parameters" id="refsect1-pdo.pgsqllobopen-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">oid</code></dt>

     <dd>

      <p class="para">
       A large object identifier.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">mode</code></dt>

     <dd>

      <p class="para">
       If mode is <code class="literal">r</code>, open the stream for reading.
       If mode is <code class="literal">w</code>, open the stream for writing.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-pdo.pgsqllobopen-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns a stream resource on success 或者在失败时返回 <strong><code>false</code></strong>.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-pdo.pgsqllobopen-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1108">
    <p><strong>示例 #1 A <span class="function"><strong>PDO::pgsqlLOBOpen()</strong></span> example</strong></p>
    <div class="example-contents"><p>
     Following on from the <span class="function"><a href="pdo.pgsqllobcreate.html" class="function">PDO::pgsqlLOBCreate()</a></span>
     example, this code snippet retrieves the large object from
     the database and outputs it to the browser.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$db&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">PDO</span><span style="color: #007700">(</span><span style="color: #DD0000">'pgsql:dbname=test&nbsp;host=localhost'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$user</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$pass</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setAttribute</span><span style="color: #007700">(</span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">ATTR_ERRMODE</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">ERRMODE_EXCEPTION</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">beginTransaction</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">prepare</span><span style="color: #007700">(</span><span style="color: #DD0000">"select&nbsp;oid&nbsp;from&nbsp;BLOBS&nbsp;where&nbsp;ident&nbsp;=&nbsp;?"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">execute</span><span style="color: #007700">(array(</span><span style="color: #0000BB">$some_id</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">bindColumn</span><span style="color: #007700">(</span><span style="color: #DD0000">'oid'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$oid</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">PARAM_STR</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetch</span><span style="color: #007700">(</span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">FETCH_BOUND</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$stream&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">pgsqlLOBOpen</span><span style="color: #007700">(</span><span style="color: #0000BB">$oid</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'r'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">"Content-type:&nbsp;application/octet-stream"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fpassthru</span><span style="color: #007700">(</span><span style="color: #0000BB">$stream</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>



 <div class="refsect1 seealso" id="refsect1-pdo.pgsqllobopen-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="pdo.pgsqllobcreate.html" class="function" rel="rdfs-seeAlso">PDO::pgsqlLOBCreate()</a> - Creates a new large object</span></li>
    <li class="member"><span class="function"><a href="pdo.pgsqllobunlink.html" class="function" rel="rdfs-seeAlso">PDO::pgsqlLOBUnlink()</a> - Deletes the large object</span></li>
    <li class="member"><span class="function"><a href="function.pg-lo-open.html" class="function" rel="rdfs-seeAlso">pg_lo_open()</a> - 打开一个大型对象</span></li>
   </ul>
  </p>
 </div>



</div></div></div></body></html>